package com.xiashitech.agent.utils;

import com.xiashitech.agent.Agent;
import com.xiashitech.agent.config.StartConfig;

import java.net.URISyntaxException;

public class LaunchPathParseUtil {

    public static String getAgentPackage() {
        String agentPath = "";
        try {
            agentPath = Agent.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
            if(System.getProperty("os.name") != null && System.getProperty("os.name").startsWith("Windows")) {
                agentPath = agentPath.startsWith("/") ? agentPath.substring(1) : agentPath;
            }
        } catch (URISyntaxException e) {
            StartConfig.throwableStackPrinter(e);
        }
        return agentPath;
    }
}
